﻿#ifndef VIDEORENDERER_H
#define VIDEORENDERER_H

#include <QQuickFramebufferObject>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
#include <QMutex>
#include <QImage>

class VideoRenderer : public QQuickFramebufferObject::Renderer, protected QOpenGLFunctions
{
public:
    VideoRenderer();
    ~VideoRenderer();

    QOpenGLFramebufferObject* createFramebufferObject(const QSize &size) override;
    void render() override;
    void synchronize(QQuickFramebufferObject *item) override;

    void updateFrame(const QImage &frame);

private:
    GLuint m_texture;
    QSize m_textureSize;
    QImage m_currentFrame;
    QMutex m_frameMutex;
    QOpenGLShaderProgram m_program;
};

#endif // VIDEORENDERER_H
